package Exception;

/*
    子类重写父类方法时，如果父类方法抛出了异常，那么子类方法抛出的异常只能比父类方法抛出的异常更加具体或者相等，
    不能大于父类方法抛出的异常。
 */
public class ExceptionDemo1 {

}
class Person{
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void printMessage() throws Exception {
        if(age<0){
            throw new  Exception("age不能为负数");
        }
        System.out.println("name:"+name+","+"age:"+age);
    }

}
class Student extends Person{
    public Student(String name, int age) {
        super(name, age);
    }

    @Override
    public void printMessage() throws AgeNegativeException {
        if(age<0){
            throw new  AgeNegativeException("age不能为负数");
        }
        System.out.println("name:"+name+","+"age:"+age);
    }
}
class AgeNegativeException extends Exception{
    public AgeNegativeException() {
    }

    public AgeNegativeException(String message) {
        super(message);
    }
}
